package com.leedcode;

import java.util.ArrayList;
import java.util.List;

/*
* LeedCode   682.棒球比赛
* */
public class LeedCode378_re {
    public static void main(String[] args) {
        String[] operations = {"5","2","C","D","+"};
        int res = calPoints(operations);
        System.out.println(res);
    }
    public static int calPoints(String[] operations) {
        int res = 0;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < operations.length; i++) {
            int size = list.size();
            String s = operations[i];
            switch (s){
                case "+" -> {
                    int temp = list.get(size-1) + list.get(size-2);
                    list.add(temp);
                    res = res + temp;
                }
                case "C" -> {
                    res = res - list.get(size-1);
                    list.remove(size - 1);
                }
                case "D" -> {
                    int temp = list.get(size-1) * 2;
                    list.add(temp);
                    res = res + temp;
                }
                default -> {
                    int num = Integer.parseInt(s);
                    list.add(num);
                    res = res + num;
                }
            }
        }
        return res;
    }
}
